package com.tedu.springdemo.day04;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * 针对于DI依赖注入
 * @Value 用于属性，给属性注入值
 */
@Component
public class Demo {
    @Value("${name}") //替代<property>
    private String name;
    @Value("${age}")
    private int age;
    @Value("#{@list1}")
    private List<String> list;
    @Value("#{@set1}")
    private Set<String> set;
    @Value("#{@map1}")
    private Map<String,Object> map;
    @Value("#{@properties1}")
    private Properties properties;//静态文件类型
    //引用类型 DI注入 @Autowired
    /**
     * @Autowired自动装配 可以完成自定义bean类型注入【属性：类】
     * 注入：两种方式 byName
     *              byType
     * 1.查@Qualifier，没有
     * 2.按照byType 类型 注入 没有
     * 3.按照byName  id     注入 没有【报错】
     * @Qualifier("p")    id方式注入
     */
    @Autowired//先按照类找、按照id找【标准写法】
    //@Qualifier("p")
    //按照id找 自动推断Pig 肯定不是p
    private Pig p;


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public List<String> getList() {
        return list;
    }

    public void setList(List<String> list) {
        this.list = list;
    }

    public Set<String> getSet() {
        return set;
    }

    public void setSet(Set<String> set) {
        this.set = set;
    }

    public Map<String, Object> getMap() {
        return map;
    }

    public void setMap(Map<String, Object> map) {
        this.map = map;
    }

    public Properties getProperties() {
        return properties;
    }

    public void setProperties(Properties properties) {
        this.properties = properties;
    }
    //打印 属性的值  重写tostring() 包.类@16进制值


    public Pig getP() {
        return p;
    }

    public void setP(Pig p) {
        this.p = p;
    }

    @Override
    public String toString() {
        return "Demo{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", list=" + list +
                ", set=" + set +
                ", map=" + map +
                ", properties=" + properties +
                ", p=" + p +
                '}';
    }
}
